package frame.networks.tables;

import java.awt.Color;
import java.awt.Component;

import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;

import model.components.networks.network.Network;

@SuppressWarnings("serial")
public class TableCellRenderer extends DefaultTableCellRenderer
{
	@Override
	public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column )
	{
		Component component = super.getTableCellRendererComponent( table,  value, isSelected, hasFocus, row, column );
		String networkStateName = table.getModel().getValueAt( row, table.getModel().getColumnCount() - 1 ).toString();
		
		if( !isSelected )
		{
			if( networkStateName.equalsIgnoreCase( Network.AVAILABLE_STATE ) )
				component.setBackground( Color.WHITE );
			
			else if( networkStateName.equalsIgnoreCase( Network.READY_STATE ) )
				component.setBackground( Color.CYAN );
			
			else if( networkStateName.equalsIgnoreCase( Network.ACCEPTED_STATE ) )
				component.setBackground( Color.GREEN );
			
			else if( networkStateName.equalsIgnoreCase( Network.REJECTED_STATE ) )
				component.setBackground( Color.RED );
			
			else
				component.setBackground( Color.WHITE );
		}
		
		return component;
	}
	
}
